﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Budget/Budget.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="LOGISTCBUS.Entities" %>
<%@ Import Namespace="LOGISTCBUS.DAO" %>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript" src="<%= Url.Content("~/Scripts/App/budgetEdit.js") %>"></script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <strong>CADASTRO DE ORÇAMENTO</strong>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%
        var b = this.ViewData["budget"] != null ? (Budget)this.ViewData["budget"] : new Budget();
    %>
    <div class="box">
        <div class="tabs">
            <ul>
                <li class="titleBox" style="padding: 3px 0 6px 10px;">Preencha os campos abaixo:</li>
            </ul>
            <div style="padding: 20px;" align="center">
                <div class="box" style="width: 500px;">
                    <div class="tabs">
                        <div style="padding: 10px;">
                            <input type="hidden" id="hdfIdBudget" value="<%= b.Id %>" />
                            <table border="0" align="center" cellpadding="0" cellspacing="5" class="texto10azulclaro">
                                <tr>
                                    <td colspan="3" align="center">
                                        <p style='color: red; font-weight: bold;' id="lblMessage">
                                            <%= ViewData["error"] %>
                                        </p>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="23" align="right">
                                        Código:
                                    </td>
                                    <td>
                                        <input type="text" name="txtCode" id="txtCode" class="fForm required" maxlength="100"
                                            disabled="disabled" style="width: 220px;" tabindex="1" value="<%= b != null && b.Id > 0 ? b.Code : new BudgetDAO().selectNextCode() %>" />
                                        <input type="hidden" id="hdfCode" value="<%= b != null && b.Id > 0 ? b.Code : new BudgetDAO().selectNextCode() %>" />
                                    </td>
                                </tr>
                                <tr>
                                    <td height="23" align="right">
                                        Viagem:
                                    </td>
                                    <td>
                                        <select id="cboTrip" name="cboTrip" class="fForm required" style="width: 221px;"
                                            tabindex="2">
                                            <option value="">--Selecione--</option>
                                            <%
                                                foreach (var t in new TripDAO().select())
                                                {
                                                    if (!String.IsNullOrEmpty(t.Code))
                                                    {
                                                        var selected = "";
                                                        if (b != null && b.Id > 0 && b.Trip != null)
                                                            if (b.Trip.Id == t.Id)
                                                                selected = " selected ";
                                            %>
                                            <option <%= selected %> value="<%= t.Id %>">
                                                <%= t.Code %>
                                            </option>
                                            <%      }
                                                }
                                            %>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="23" align="right">
                                        Clientes:
                                    </td>
                                    <td>
                                        <div style="float: left;">
                                            <select id="cboCustomers" class="fForm" style="width: 100px; height: 105px;" multiple="multiple"
                                                tabindex="3">
                                                <%
                                                    foreach (var c in new CustomerDAO().selectCustomers(b.Id, true))
                                                    {
                                                        if (!String.IsNullOrEmpty(c.Name))
                                                        {
                                                            var selected = "";
                                                %>
                                                <option <%= selected %> value="<%= c.Id %>">
                                                    <%= c.Name %>
                                                </option>
                                                <%      }
                                                    }
                                                %>
                                            </select>
                                        </div>
                                        <div style="float: left;">
                                            <ul id='icons' class='ui-widget ui-helper-clearfix'>
                                                <li class='ui-state-default ui-corner-all' title='Mover Todos'><a href='#' id='lnkBackAll'>
                                                    <span class='ui-icon ui-icon-seek-first'></span></a></li>
                                                <br />
                                                <br />
                                                <li class='ui-state-default ui-corner-all' title='Mover para Direita'><a href='#'
                                                    id='lnkMoveLeft'><span class='ui-icon ui-icon-seek-prev'></span></a></li>
                                                <br />
                                                <br />
                                                <li class='ui-state-default ui-corner-all' title='Mover para Esquerda'><a href='#'
                                                    id='lnkMoveRight'><span class='ui-icon ui-icon-seek-next'></span></a></li>
                                                <br />
                                                <br />
                                                <li class='ui-state-default ui-corner-all' title='Voltar Todos'><a href='#' id='lnkMoveAll'>
                                                    <span class='ui-icon ui-icon-seek-end'></span></a></li>
                                            </ul>
                                        </div>
                                        <div style="float: right;">
                                            <select id="cboCustomersLinked" class="fForm" style="width: 100px; height: 105px;"
                                                multiple="multiple" tabindex="4">
                                                <%
                                                    foreach (var c in new CustomerDAO().selectCustomers(b.Id, false))
                                                    {
                                                        if (!String.IsNullOrEmpty(c.Name))
                                                        {
                                                            var selected = "";
                                                %>
                                                <option <%= selected %> value="<%= c.Id %>">
                                                    <%= c.Name %>
                                                </option>
                                                <%      }
                                                    }
                                                %>
                                            </select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="23" align="right">
                                        Data de Validade:
                                    </td>
                                    <td>
                                        <% 
                                            var validateDate = string.Empty;
                                            var lst = new BudgetCustomerDAO().selectByBudget(b.Id);
                                            if (lst != null && lst.Count > 0)
                                            {
                                                var obj = lst.FirstOrDefault();
                                                if (obj != null && obj.ValidateDate.HasValue)
                                                    validateDate = Convert.ToDateTime(obj.ValidateDate).ToString("dd/MM/yyyy");
                                            }
                                        %>
                                        <input type="text" name="txtValidateDate" id="txtValidateDate" class="fForm datefield required"
                                            maxlength="10" style="width: 220px;" tabindex="5" value="<%= !String.IsNullOrEmpty(validateDate) ? validateDate : string.Empty %>" />
                                    </td>
                                </tr>
                                <tr>
                                    <td height="23" align="right">
                                        Valor:
                                    </td>
                                    <td>
                                        <input type="text" name="txtValue" id="txtValue" class="fForm decimalfield required"
                                            maxlength="100" style="width: 220px;" tabindex="6" value="<%= b.Value > Decimal.Zero ? b.Value.ToString() : string.Empty %>" />
                                    </td>
                                </tr>
                                <tr>
                                    <td height="23" align="right" valign="middle">
                                        Descrição:
                                    </td>
                                    <td>
                                        <textarea id="txtDescription" rows="3" cols="100" class="fForm" style="width: 220px;
                                            height: 100px;" maxlength="500" tabindex="7"><%= b.Description %></textarea>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
                <div style="padding-top: 10px;">
                    <input name="btnSave" id="btnSave" type="button" value="Inserir" class="ui-button ui-state-default ui-corner-all botaoS"
                        tabindex="8" />
                </div>
            </div>
        </div>
    </div>
    <div align="center" class="texto10azulclaro" style="padding-top: 15px;">
        © 2012 - Todos os direitos reservados.
    </div>
</asp:Content>
